package chapter03

import org.apache.log4j.{Level, Logger}
import org.apache.spark.{SparkConf, SparkContext}

object Test38_house {
  def main(args: Array[String]): Unit = {
    Logger.getLogger("org.apache.spark").setLevel(Level.WARN)
    val conf = new SparkConf().setAppName("house")
    val sc = new SparkContext(conf)
    //读取文件
    val input = args(0)
    val value = sc.textFile(input)
    val value1 = value.map(e => e.split("\t"))
    val value2 = value1.filter(e => !e(5).equals(""))
    println(value2.map(e=>e.toList).take(2).toList)
    //每个地点的可以租房的总数
    val value3 = value2
      .map(e => (e(3), e(6).toInt)).reduceByKey(_ + _)
    println(value3.collect().toList)
    val output = args(1)
    value3.saveAsTextFile(output)
  }
}
